package io.gitee.thghh.generate.core.config;

import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.logicdelete.LogicDeleteManager;
import com.mybatisflex.core.logicdelete.impl.DateTimeLogicDeleteProcessor;
import com.mybatisflex.core.logicdelete.impl.TimeStampLogicDeleteProcessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

/**
 * mybatis-flex配置
 *
 * @author pengzhikang
 * @date 2025/03/28 13:24
 * @since 1.0.0
 */
@Slf4j
@Configuration
public class MyBatisFlexConfiguration {

    public MyBatisFlexConfiguration() {
        // 开启审计功能
        AuditManager.setAuditEnable(true);

        // 设置 SQL 审计收集器
        AuditManager.setMessageCollector(m -> log.info("{},{}ms", m.getFullSql(), m.getElapsedTime()));

        // 逻辑删除处理器
        log.info("set logic delete process = TimeStampLogicDeleteProcessor");
        LogicDeleteManager.setProcessor(new TimeStampLogicDeleteProcessor());
    }
}